package com.dangdang.recursion;

public class PowSolution {


    public static double solution(int x, int n){
        double result = 0;
        result = pow(x,n);

        return result;
    }


    private static double pow(int x, int n){
        if (n == 0){
            return 1;
        }

        double result = pow(x,n/2);

        if (n%2 == 0) {
            return result*result;
        }else {
            return result*result*x;
        }
    }


    public static void main(String[] args) {
        double result = PowSolution.pow(2,9);
        System.out.println(result);
    }

}
